<#include "/common/defaultEngine.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="合同" bodyClass="white-bg" libs=["bootstrapSelect"]/>
<div class="wrapper wrapper-content ibox-content">
    <@f.form id="task-form-complete" class="form-horizontal">
    <h4 class="form-header h4"><@ctx.i18n text = "基本信息"/></h4>
    <input class="form-control" name="id" value="${contract.id?default('')}" type="hidden"  >

    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "甲方"/>：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->
                        <@f.tableselect checked=false keyId="participantName" keyName="participantName" url="/pms/participant/list"
                        value="${contract.firsts?default('')}"
                        labelValue="${contract.firsts?default('')}"
                        name="firsts" boxTitle="甲方" tableInfo = "[{field:'participantCode',title:'参建编号'},
                        {field:'participantName',title:'参建名称'}, {field:'projectName',title:'工程名称'}]" placeholder="请选择甲方" />
                        <!--<input class="form-control" name="first" value="${contract.first?default('')}" type="text"  >-->
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "乙方"/>：</label>
                <div class="col-sm-8">
                    <@f.tableselect checked=false keyId="participantName" keyName="participantName" url="/pms/participant/list"
                    value="${contract.seconds?default('')}"
                    labelValue="${contract.seconds?default('')}"
                    name="seconds" boxTitle="甲方" tableInfo = "[{field:'participantCode',title:'参建编号'},
                    {field:'participantName',title:'参建名称'}, {field:'projectName',title:'工程名称'}]" placeholder="请选择甲方" />
                    <!--<input class="form-control" name="second" value="${contract.second?default('')}" type="text"  >-->
                </div>
            </div>
        </div>
    </div>

    <div class="row">
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "项目名称"/>：</label>
                <div class="col-sm-8">
                    <!--<input class="form-control" name="projectName" value="" type="text"  >-->
                    <!--   中国-{YMD}{序号} -->
                    <@f.tableselect checked=false keyId="projectName" keyName="projectName" url="/pms/participant/list"
                    value="${contract.projectName?default('')}"
                    labelValue="${contract.projectName?default('')}"
                    name="projectName" boxTitle="甲方" tableInfo = "[{field:'participantCode',title:'参建编号'},
                    {field:'participantName',title:'参建名称'}, {field:'projectName',title:'工程名称'}]" placeholder="请选择甲方" />
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "合同金额"/>：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->

                        <input class="form-control" name="amount" value="${contract.amount?default('')}" type="text"  >
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "签订时间"/>：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        <input type="text" class="time-input" id="signAt" placeholder="签订时间"
                               value="${contract.signAt?string('yyyy-MM-dd HH:mm:ss')}" name="signAt"
                               data-type="datetime" data-format="yyyy-MM-dd HH:mm:ss"/>

                        <!--readonly="true"-->
                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "签订地点"/>：</label>
                <div class="col-sm-8">
                    <div class="input-group date">
                        <!--<span class="input-group-addon"><i class="fa fa-calendar"></i></span>-->

                        <input class="form-control" name="signAddr" value="${contract.signAddr?default('')}" type="text"  >
                    </div>
                </div>
            </div>
        </div>


    </div>

    <div class="row">

        <div class="col-sm-6">
            <div class="form-group">
                <label class="col-sm-4 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "上传合同"/>：</label>
                <div class="col-sm-8">
                    <input type="file" id="contractUrl"  style="padding-top: 4px;"/>
                    <input name="contractUrl" value="${contract.contractUrl?default('')}" type="hidden" >
                </div>
            </div>
        </div>
    </div>


    <div class="row">
        <div class="col-sm-12">
            <div class="form-group">
                <label class="col-sm-2 control-label"><span style="color: red; ">*</span><@ctx.i18n text = "备注"/>：</label>
                <div class="col-sm-10">
                    <@f.textarea name="remark" rows="3" value="${contract.remark?default('')}" />
                    <!--<input class="form-control" name="remark" value="" type="text"  >-->
                </div>
            </div>
        </div>
    </div>


</div>




</@f.form>
<div class="hr-line-dashed"></div>
<div class="row" style="text-align: center;" id="_addTab">
    <!--<button type="button" class="btn btn-sm btn-primary" onclick="opt.form.submit()"><i class="fa fa-check"></i><@ctx.i18n text = "保存"/></button>&nbsp;-->
    <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i><@ctx.i18n text = "保存"/></button>&nbsp;
    <button type="button" class="btn btn-sm btn-danger" onclick="opt.modal.closeTab()"><i class="fa fa-reply-all"></i><@ctx.i18n text = "关闭"/></button>
</div>
</div>
<@footer>
<script type="text/javascript">
    var prefix = baseURL + "pms/contract";

    $('#tipBut button').click(function(){
        $('#comment').text($(this).text())
    });

    $("#task-form-complete").validate({
        focusCleanup: true
    });

    function submitHandler() {

        //  var arrivalAmount= parseFloat($('input[name="arrivalAmount"]').val());
        //  var claimAmount= parseFloat($('input[name="claimAmount"]').val());
        //  console.log(arrivalAmount);
        //  console.log(claimAmount);
        //  console.log(claimAmount>arrivalAmount);
        // if(claimAmount>arrivalAmount){
        //   //  alert("已认领金额不能大于到账金额");
        //   return  opt.modal.alertWarning("已认领金额不能大于到账金额");
        // }

        if (opt.validate.form()) {
            opt.operate.saveTab(prefix + "/edit", $('#task-form-complete').serialize());
        }


    }
    /*上传操作规程*/
    $("#contractUrl").change(function () {
        uploadFile();
    });
    function uploadFile() {
        var oFiles = document.getElementById("contractUrl").files;
        console.log("1111");
        console.log(oFiles);
        var formdata = new FormData();
        console.log("2222");
        formdata.append("file", oFiles[0]);
        console.log("333");
        console.log(formdata)
        console.log("4444");
        opt.common.sendAjax({
            url: prefix + "/doUploadFile",
            data: formdata,
            type: "POST",
            processData: false,
            contentType: false,
            success: function(result) {
                console.log("55555");
                console.log(result.data);
                console.log(result.data);
                console.log(result);
                $("input[name=contractUrl]").val(result.data);
                console.log("1111111111");
                console.log(result);
                console.log(result);
            }
        })
    }
</script>
</@footer>
</@pageTheme>